var dynamicLoading = {
    css: function (path) {
        if (!path || path.length === 0) {
            throw new Error('argument "path" is required !');
        }
        var head = document.getElementsByTagName('head')[0];
        var link = document.createElement('link');
        link.href = path;
        link.rel = 'stylesheet';
        link.type = 'text/css';
        head.appendChild(link);
    },
    js: function (path) {
        if (!path || path.length === 0) {
            throw new Error('argument "path" is required !');
        }
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.src = path;
        script.type = 'text/javascript';
        head.appendChild(script);
    }
};
dynamicLoading.js("/seeyon/ajax.do?managerName=qiangsDDManager");
dynamicLoading.js("/seeyon/ajax.do?managerName=qiangsSeepManager");

window.thirdPartyFormAPI.registerEvent('afterFormFieldChange', function(params){
	var display=params.display;
	var showValue=params.showValue;
	try{
		if(display == '公司负责人')	{
			var data = window.thirdPartyFormAPI.getFormData();
			var ddManager = new qiangsDDManager();
			if($.trim(params.value) == ""){
				return ;
			}
			ddManager.updateKeyMemberInfo(0, data.formData.content.contentDataId+"", params.value, 
				data.formData.content.contentTemplateId+"",{
	            success: function(returnVal){
	                if("0" != returnVal){
						data.formsons.front_formson_15.records[2].lists.field0217.relationData.toMasterDataId;
						for(var i=0; i < data.formsons.front_formson_15.records.length; i++){
							if(data.formsons.front_formson_15.records[i].lists.field0217.relationData.toMasterDataId
								== returnVal){
								data.formsons.front_formson_15.records[i].lists.field0217.value = params.value;
								data.formsons.front_formson_15.records[i].lists.field0217.showValue = params.value;
								data.formsons.front_formson_15.records[i].lists.field0217.valueId = params.value;
							}
						}
					}
	            }
			});
		} else if(display == '业务联系人')	{
			var data = window.thirdPartyFormAPI.getFormData();
			var ddManager = new qiangsDDManager();
			if($.trim(params.value) == ""){
				return ;
			}
			ddManager.updateKeyMemberInfo(1, data.formData.content.contentDataId+"", params.value,  
					data.formData.content.contentTemplateId+"",{
	            success: function(returnVal){
	                if("0" != returnVal){
						data.formsons.front_formson_15.records[2].lists.field0217.relationData.toMasterDataId;
						for(var i=0; i < data.formsons.front_formson_15.records.length; i++){
							if(data.formsons.front_formson_15.records[i].lists.field0217.relationData.toMasterDataId
								== returnVal){
								data.formsons.front_formson_15.records[i].lists.field0217.value = params.value;
								data.formsons.front_formson_15.records[i].lists.field0217.showValue = params.value;
								data.formsons.front_formson_15.records[i].lists.field0217.valueId = params.value;
							}
						}
					}
	            }
			});
		} else if(display == '企业负责人')	{
			var data = window.thirdPartyFormAPI.getFormData();
			var ddManager = new qiangsDDManager();
			if($.trim(params.value) == ""){
				return ;
			}
			ddManager.updateKeyMemberInfo(2, data.formData.content.contentDataId+"", params.value,  
					data.formData.content.contentTemplateId+"",{
	            success: function(returnVal){
	                if("0" != returnVal){
						data.formsons.front_formson_15.records[2].lists.field0217.relationData.toMasterDataId;
						for(var i=0; i < data.formsons.front_formson_15.records.length; i++){
							if(data.formsons.front_formson_15.records[i].lists.field0217.relationData.toMasterDataId
								== returnVal){
								data.formsons.front_formson_15.records[i].lists.field0217.value = params.value;
								data.formsons.front_formson_15.records[i].lists.field0217.showValue = params.value;
								data.formsons.front_formson_15.records[i].lists.field0217.valueId = params.value;
							}
						}
					}
	            }
			});
		}
	} catch(e){}
});